# Maintainer: David Runge <dvzrv@archlinux.org>
# Contributor: Alexander Epaneshnikov <aarnaarn2@gmail.com>
# Contributor: Tom Gundersen <teg@jklm.no>
# Contributor: Jan de Groot <jgc@archlinux.org>
# Contributor: Giovanni Scafora <giovanni@archlinux.org>

pkgname=brltty
pkgver=6.4
pkgrel=1
pkgdesc="Braille display driver for Linux/Unix"
arch=('x86_64')
url="https://brltty.app"
license=('LGPL2.1')
depends=('bluez-libs' 'gcc-libs' 'glibc' 'liblouis' 'libspeechd' 'pcre2'
'polkit' 'tcl')
makedepends=('alsa-lib' 'at-spi2-atk' 'at-spi2-core' 'atk' 'cython' 'dbus'
'dracut' 'espeak-ng' 'expat' 'festival' 'glib2' 'gpm' 'icu' 'java-environment'
'libxaw' 'ncurses' 'ocaml-ctypes' 'ocaml-findlib' 'speech-dispatcher'
'systemd-libs')
optdepends=('at-spi2-core: X11/GNOME Apps accessibility'
            'atk: ATK bridge for X11/GNOME accessibility'
            'espeak-ng: espeak-ng driver'
            'java-runtime: Java support'
            'libxaw: X11 support'
            'libxt: X11 support'
            'libx11: for xbrlapi'
            'libxfixes: for xbrlapi'
            'libxtst: for xbrlapi'
            'ocaml: OCaml support'
            'python: Python support'
            'speech-dispatcher: speech-dispatcher driver')
provides=('libbrlapi.so')
backup=(etc/brltty.conf)
options=('!emptydirs')
install=brltty.install
source=("https://brltty.app/archive/${pkgname}-${pkgver}.tar.bz2"
        "${pkgname}-6.2-systemd_sysusers_groups.patch"
)
sha512sums=('58394c18d56a2a93a44be1c5dcfd02613581820ea2d2dbd945372ea11e066a18a75832ea04f09cf7f411e6dd1cd4ec78574f317dafcbc5c431dcf0db21b93690'
            '32ba91271e2247b4a330cd213ed75b591268cb99a79c2efd9ae675804faee027c6b2f782768cb2329a65fc914ca2400b2901f35ce1fc2522c6691b343799eb02')
b2sums=('2c31b8282f0bc4730e406772c8b5aa72b1650e3290cfe967ec668394627440f84afe936bfbdbdab9ee0e7ba93ef466950295dbd7d979b639605fe619b5c170bd'
        '036e36d558594bb06af1eb41ff5fc9ae52ccf4bad54556c3f4f81a5e2f31f574039835e5e756455527c327a73d563a3db54a9f32e3478545a2a22c2725aaeee2')

prepare() {
  cd "${pkgname}-${pkgver}"
  patch -Np1 -i ../"${pkgname}-6.2-systemd_sysusers_groups.patch"
  ./autogen
}

build() {
  cd "${pkgname}-${pkgver}"
  ./configure --prefix=/usr \
              --sysconfdir=/etc \
              --localstatedir=/var \
              --mandir=/usr/share/man \
              --with-scripts-directory=/usr/lib/brltty \
              --with-tables-directory=/usr/share/brltty \
              --with-writable-directory=/run/brltty \
              --enable-gpm \
              --disable-stripping
  make
}

package() {
  depends+=('libasound.so' 'libdbus-1.so' 'libexpat.so' 'libgio-2.0.so'
  'libglib-2.0.so' 'libgobject-2.0.so' 'libicuuc.so' 'libgpm.so'
  'libncursesw.so' 'libsystemd.so')
  cd "${pkgname}-${pkgver}"
  make INSTALL_ROOT="${pkgdir}" install
  make INSTALL_ROOT="${pkgdir}" install-systemd
  make INSTALL_ROOT="${pkgdir}" install-udev
  # dracut support may still be problematic
  # https://bugs.archlinux.org/task/69424
  # https://bugs.archlinux.org/task/69440
  make INSTALL_ROOT="${pkgdir}" install-dracut
  make INSTALL_ROOT="${pkgdir}" install-polkit
  install -vDm 644 "Documents/${pkgname}.conf" -t "${pkgdir}/etc/"

  # fix directory permission and ownership
  install -vdm 750 -o root -g 102 "$pkgdir/usr/share/polkit-1/rules.d"
}
